<template>
  <div class="messge">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align:center">
          <el-form-item label="状态">
              <el-input v-model="param.status" placeholder="请输入内容"></el-input>
          </el-form-item>
        <el-form-item>
            <el-button size="small" type="primary" icon="el-icon-search" @click="loadmessage">搜索
            </el-button>
        </el-form-item>
          </el-form>  
    <div style="text-align:right"> 
      <div style="text-align-right">
         <el-button type="primary" size="small" @click="toAndHander">新增</el-button>
         <el-button type="primary" size="small" @click="downloadHandler">导出</el-button>
      </div>
     
    </div>
    </div>
    <!-- /按钮 -->                            
    
    <!-- 表格 -->
    <el-table size="small" :data="message">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="id" prop="id" align="center"></el-table-column>
      <el-table-column label="问题" prop="question" align="center"></el-table-column>
      <el-table-column label="问题时间" prop="questionTime" align="center"></el-table-column>
      <el-table-column label="回复" prop="reply" align="center"></el-table-column>
      <el-table-column label="回复时间" prop="replayTime" align="center"></el-table-column>
      <el-table-column label="status" prop="status" align="center"></el-table-column>
      <el-table-column label="professor_id" prop="professorId" align="center"></el-table-column>
      <el-table-column label="user_id" prop="userId" align="center"></el-table-column>
            <el-table-column label="操作" width="130" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
                      <el-button type="text" style="color:greenbule" size="mini" icon="el-icon-edit" @click="editHandler(scope.row)">修改</el-button >
          <el-button type="text" style="color:red" size="mini" icon="el-icon-delete-solid" @click="deleteHandler(scope.row)">删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import {del, get,post} from '@/utils/request'
export default {
  // 页面数据
  data(){
    return {

    param:{},
      message:[]
    }
  },
  // 页面渲染的时候会调用的函数
  created(){
    this.loadmessage();
  },
  // 所有的方法
  methods:{
    downloadHandler(){
      window.location.href="http://8.131.68.179:9999/greenhouse_message/download?status="+this.param.status
    },

     editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/counsel/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
      deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/greenhouse_message/deleteByID";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadmessage();
        });
      });
    },


    toAndHander(){
        this.$router.push("/counsel/create")
    },

    loadmessage(){
      
      let url = 'http://8.131.68.179:9999/greenhouse_message/query'
      get(url,this.param).then(resp=>{
        this.message = resp.data;
      })
    }
  }
}
</script>
<style scoped>
.btns{
    margin-bottom: .5em;
    margin-left: .10em;
}
 

</style>